package com.zaimokuza.cn.controller;

import com.zaimokuza.cn.entity.response.ResponseFormat;
import com.zaimokuza.cn.service.FollowService;
import com.zaimokuza.cn.service.LikeService;
import com.zaimokuza.cn.util.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zaimokuza
 */
@Api(tags = "用户操作相关接口，例如：关注，点赞等")
@ResponseFormat
@RestController
@RequestMapping("/operate")
public class OperateController {

    @Resource
    private FollowService followService;
    @Resource
    private LikeService likeService;

    @ApiOperation(value = "添加关注", notes = "添加对应的关注关系")
    @PostMapping("/follow/{targetUserId}")
    @Transactional(rollbackFor = Exception.class)
    public void follow(@PathVariable @ApiParam("目标用户ID") String targetUserId) {
        followService.follow(targetUserId, UserUtils.getUserId());
    }

    @ApiOperation(value = "取消关注", notes = "取消对应的关注关系")
    @DeleteMapping("/unfollow/{targetUserId}")
    @Transactional(rollbackFor = Exception.class)
    public void unfollow(@PathVariable @ApiParam("目标用户ID") String targetUserId) {
        followService.unfollow(targetUserId, UserUtils.getUserId());
    }

    @ApiOperation(value = "点赞博客", notes = "点赞博客")
    @PostMapping("/like/blog/{blogId}")
    @Transactional(rollbackFor = Exception.class)
    public void likeBlog(@PathVariable String blogId) {
        likeService.likeBlog(blogId, UserUtils.getUserId());
    }

    @ApiOperation(value = "取消点赞博客", notes = "取消点赞博客")
    @DeleteMapping("/unlike/blog/{blogId}")
    @Transactional(rollbackFor = Exception.class)
    public void unlikeBlog(@PathVariable String blogId) {
        likeService.unlikeBlog(blogId, UserUtils.getUserId());
    }

    @ApiOperation(value = "点赞评论", notes = "点赞评论")
    @PostMapping("/like/comment/{commentId}")
    @Transactional(rollbackFor = Exception.class)
    public void likeComment(@PathVariable String commentId) {
        likeService.likeComment(commentId, UserUtils.getUserId());
    }

    @ApiOperation(value = "取消点赞评论", notes = "取消点赞评论")
    @DeleteMapping("/unlike/comment/{commentId}")
    @Transactional(rollbackFor = Exception.class)
    public void unlikeComment(@PathVariable String commentId) {
        likeService.unlikeComment(commentId, UserUtils.getUserId());
    }

}
